<%@ include file="/WEB-INF/templates/jsp/include.jsp"%>
<%@ taglib prefix="basic" uri="http://ciracas.basic.org/tags-ui"%>

<script type="text/javascript">
    var intCbObject;
    var deleteParam;

    function doCheck(cbObject, paramROWID) {
        with (document.getElementById("commandIdentification"))
        {
            if (selectedRecord.length != null)
            {
                for (var i = 0; i < selectedRecord.length; i++)
                {
                    if (selectedRecord[i] == cbObject)
                    {
                        if (intCbObject != i)
                        {
                            intCbObject = i;
                            deleteParam = paramROWID;
                        }
                        else
                        {
                            selectedRecord[i].checked = false;
                            intCbObject = null;
                            deleteParam = null;
                        }
                    }
                    else
                    {
                        selectedRecord[i].checked = false;
                    }
                }
            }
            else
            {
                if (selectedRecord.checked)
                {
                    deleteParam = paramROWID;
                }
                else
                {
                    deleteParam = null;
                }
            }
        }
    }

    function doSearch()
    {
        with (document.getElementById("commandIdentification"))
        {
        	strAction.value = '<%=com.common.basic.util.Globals.ACTION_SEARCH%>';
            submit();
        }
    }
	
    function doDelete()
    {
        with (document.getElementById("commandIdentification"))
        {
        	strAction.value = '<%=com.common.basic.util.Globals.ACTION_DELETE%>';
            action = "<%=request.getContextPath()%><spring:message code="app.url.base"/>/master/identity/delete";
            submit();
        }
    }
	
    function doAdd()
    {
        with (document.getElementById("commandIdentification"))
        {
        	strAction.value = '<%=com.common.basic.util.Globals.ACTION_ADD%>';
            action = "<%=request.getContextPath()%><spring:message code="app.url.base"/>/master/identity/form";
            method = "GET";
            submit();
        }
    }
	
    function clearCheckBox()
    {
        with (document.getElementById("commandIdentification"))
        {
            try
            {
                if (selectedRecord.length != null) {
                    for (var i = 0; i < selectedRecord.length; i++)
                    {
                        selectedRecord[i].checked = false;
                    }
                }
                else
                {
                    selectedRecord.checked = false;
                }
            }
            catch(e) {
            }
        }
    }
</script>

<form:form commandName="commandIdentification"
	action="${pageContext.request.contextPath}/basic/master/identity/viewList">
	<form:hidden path="strAction" />

	<table align="center" width="80%" border="0" cellspacing="0"
		cellpadding="4">
		<tr>
			<td align="left"><basic:button type="button"
				title="button.delete" onclick="doDelete();" /> <basic:button
				type="button" title="button.add" onclick="doAdd();" /></td>
			<td align="left"><select name="searchBy" class="selectStyle">
				<option value=""></option>
				<option value="0"
					<c:if test="${commandIdentification.searchBy == '0'}">
							selected="selected"
						</c:if>><spring:message
					code="label.name" /></option>
				<option value="1"
					<c:if test="${commandIdentification.searchBy == '1'}">
							selected="selected"
						</c:if>><spring:message
					code="label.createBy" /></option>
				<option value="2"
					<c:if test="${commandIdentification.searchBy == '2'}">
							selected="selected"
						</c:if>><spring:message
					code="label.changedBy" /></option>
			</select>&nbsp;<input type="text" name="searchValue" size="30"
				value="${commandIdentification.searchValue}">&nbsp;&nbsp;<basic:button
				type="button" title="button.search" onclick="doSearch()" /></td>

		</tr>
	</table>
	<c:if test="${not empty commandIdentification.msgList}">
		<br>
		<div style="color: red; font-size: 12;">
		<ul>
			<c:forEach items="${commandIdentification.msgList}" var="errMsg"
				varStatus="errMsgSt">
				<li>${errMsg}
			</c:forEach>
		</ul>
		</div>
	</c:if>
	<br>
	<a name="loclist" /> <display:table id="row" class="tag" name="list"
		style="width: 80%; align: center;" requestURI="#loclist">
		<display:column style="width: 15px; align: center;">
			<form:checkbox path="selectedRecord" value="${row.id }"
				onclick="doCheck(this,'${row.id}')" />
		</display:column>
		<display:column titleKey="label.code" property="code"
			sortable="true" />
		<display:column titleKey="label.name" property="name"
			sortable="true" />
		<display:column titleKey="label.createBy" property="createdby"
			sortable="true" />
		<display:column titleKey="label.createDt" property="createddate"
			sortable="true" />
		<display:column titleKey="label.changedBy" property="changedby"
			sortable="true" />
		<display:column titleKey="label.changedDt" property="changeddate"
			sortable="true" />
		<display:column style="align: center;" titleKey="label.edit"
			sortable="false" url="/basic/master/identity/form" paramId="id"
			paramProperty="id">
			<img style="align: center;" src="${themepath}/images/edit.png" />
		</display:column>
	</display:table>
</form:form>